/*******************************************************************************
 * Copyright (c) 2008 Sylvain Sicard.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Sylvain Sicard - initial API and implementation
 ******************************************************************************/
/*
 * Created on Feb 27, 2006
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package fr.jade.event.filters;

import java.util.LinkedList;
import java.util.List;

import fr.jade.event.Event;
import fr.jade.util.JadeException;

public class SingletonEventFilterImpl extends BaseEventFilter {
  
  protected List<Integer> ignored = new LinkedList<Integer>();
  
  public void handleEvent(Event e) throws JadeException {
    assert e != null;
    assert e.getEventHeader() != null;
    assert e.getEventBody() != null;
    
    boolean contains;
    synchronized(ignored){
      contains = ignored.contains(e.hashCode());
      if ( ! contains ){
        ignored.add(e.hashCode());
      }
    }
    if( ! contains ){
      log("Handle new event");
      eh.handleEvent(e);
    }else{
      log("Handle duplicate event");
    }
  }

}
